let nunjucks = require('nunjucks')
let express = require('express')
let path = require('path')

// 字符串得转义
// nunjucks.configure({autoescape:true})  //自动转义
//  let resulet= nunjucks.renderString('Hello {{ username }}', { username: '王萌' });
// return

// 文件得转义
// nunjucks.configure('views', { autoescape: true });
// let resulet= nunjucks.render('index.html', { foo: 'bar' });
// console.log(1,resulet)
// return

var app = express();

nunjucks.configure( path.resolve('views')  , {
    autoescape: true,
    express: app//通过这个属性就实现了nunjucks和express的关联
});

app.get('/', function (req, res) {
    console.log('===========' ,res.render)
    res.render('index.html',{foo:'恭喜你看见我了1002-master'});
});
app.get('/api', function (req, res) {
    console.log('===========' ,res.render)
    res.render('index.html',{foo:'恭喜你看见我了api-1002'});
});

app.listen(1002,function(err){ 
    console.log('端口:::1002')
})
// 启动https服务需要https包
// 读取文件需要fs包
//const https = require('https');
//const fs = require('fs');
//// 将两个证书文件读取放到options对象中
//// 使用readFileSync()方法，顺序地执行读文件和启动服务操作
//const options = {    
//key: fs.readFileSync('/www/server/nginx/conf/ssl/api.key'),
//cert: fs.readFileSync('/www/server/nginx/conf/ssl/api.crt')
//};
//
//// 创建服务器，启动服务器，设置监听端口号
//https.createServer(options, (req, res) => {   
//    res.end('hello world\n');
//}).listen(1000);